package com.zhentao.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhentao.pojo.ShopServiceOffering;
import com.zhentao.pojo.ShopServiceOfferings;
import com.zhentao.service.ShopServiceOfferingService;
import com.zhentao.util.Result;
import com.zhentao.vo.ShopServiceVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shop/service")
public class ShopServiceController {

    @Resource
    private ShopServiceOfferingService shopServiceOfferingService;

    /**
     * 获取门店服务详情
     */
    @RequestMapping("/{id}")
    public Result getShopServiceDetail(@PathVariable Long id) {
        ShopServiceVO detail = shopServiceOfferingService.getShopServiceDetail(id);
        return Result.OK(detail);
    }

    /**
     * 分页查询门店服务
     */
    @RequestMapping("/page")
    public Result pageShopServices(@RequestBody com.zhentao.pojo.Page page) {
        Page<ShopServiceOffering> page1 = new Page<>(page.getPageNum(), page.getPageSize());
        QueryWrapper<ShopServiceOffering> queryWrapper = new QueryWrapper<>();
        Page<ShopServiceOffering> result = shopServiceOfferingService.page(page1,queryWrapper);
        return Result.OK(result);
    }

    /**
     * 获取指定门店的所有服务
     */
    @RequestMapping("/shop/{shopId}")
    public Result getShopServices(@PathVariable Long shopId) {
        List<ShopServiceVO> services = shopServiceOfferingService.listServicesByShopId(shopId);
        return Result.OK(services);
    }

    /**
     * 添加门店服务
     */
    @RequestMapping
    public Result addShopService(@RequestBody ShopServiceOffering shopService) {
        shopServiceOfferingService.save(shopService);
        return Result.OK(shopService);
    }

    /**
     * 更新门店服务
     */
    @RequestMapping("/upd")
    public Result updateShopService(@RequestBody ShopServiceOffering shopService) {
        return Result.OK(shopServiceOfferingService.updateById(shopService));
    }

    /**
     * 删除门店服务
     */
    @RequestMapping("/delete")
    public Result deleteShopService(@PathVariable Long id) {
        return Result.OK(shopServiceOfferingService.removeById(id));
    }
}
